/*
 ----------------------------------------------------------------------------------
                           "THE BEER-WARE COPYRIGHT LICENSE"
                                     (Revision 43)
                                      -----------
    Rymek [rymek@rymek.org] wrote this file. As long as You retain this notice and
    this file has been sent directly to You by the author, You can do whatever You
    want with this stuff as long as You don't sell or rent it. If we meet some day,
    and You think this stuff is worth it, You can buy me a beer in return :-)
                                                                 __________
                                                                 Paweł Rymaszewski
  ----------------------------------------------------------------------------------
 */

package ui.windows.forms.searchForm;

import processing.objects.Result;
import ui.windows.forms.searchResult.SearchResultForm;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @author rymek
 *         User: Rymek
 *         Date: 24.07.11
 *         Time: 19:19
 */
class SearchFormMouseAdapter extends MouseAdapter {

    private final SearchForm searchForm;        // parent Search Form
    private Result selectedResult;              // selected Result

    /**
     * Constructor.
     * Creates reference for parent JList and parsed search results
     *
     * @param searchForm parent searchForm
     */
    public SearchFormMouseAdapter(SearchForm searchForm) {
        this.searchForm = searchForm;
    }

    @Override
    /**
     * Handles mouse click event
     */
    public void mouseClicked(MouseEvent e) {


        if (e.getClickCount() == 1) {
            this.selectedResult = this.searchForm.getSelectedResult();
        }
        if (e.getClickCount() == 2) {
            new SearchResultForm(this.selectedResult, this.searchForm.getParsedResults()).createResultForm();
        }
    }
}
